package util;

import java.util.*;

/**
 * @author Mark
 * @date 2020/6/9 14:33
 * @description Map和List集合问题
 */
public class ListMapDemo {

    public static void main(String[] args) {

        // 一对多和多对一的概念(list中有map)
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>(16);
        map.put("1", 1);
        map.put("2", 2);
        map.put("3", 3);
        map.put("4", 4);
        map.put("5", 5);
        list.add(map);

        // 再次遍历输出list中的map元素
        for (Map<String, Object> stringObjectMap : list) {
            System.out.println("stringObjectMap.get(\"1\") = " + stringObjectMap.get("1"));
            Set<Map.Entry<String, Object>> entries = stringObjectMap.entrySet();
            for (Map.Entry<String, Object> entry : entries) {
                System.out.println("key值 = " + entry.getKey() + "\n" + "values值 = " + entry.getValue());
            }
        }

        // 一对多和多对一的概念(map中的list)
        System.out.println("###########################################################################");
        Map<List<String>, Object> objectObjectHashMap = new HashMap<>(16);
        ArrayList<String> objects = new ArrayList<>();
        objects.add("1");
        objects.add("2");
        objects.add("3");
        objects.add("4");
        objectObjectHashMap.put(objects, 2);
        Set<Map.Entry<List<String>, Object>> entries = objectObjectHashMap.entrySet();
        for (Map.Entry<List<String>, Object> entry : entries) {
            System.out.println("entry.getKey() = " + entry.getKey());
            System.out.println("entry.getValue() = " + entry.getValue());
        }
    }
}
